class TwoSum{
    sum(num1:number[],num2:number){
        for (let i = 0; i < num1.length; i++) {
            for (let j = i+1; j < num1.length; j++) {
                console.log(i,j)
                if((num1[i] + num1[j]) === num2){
                    return [i,j]
                }
            }
        }
    }
    sumHas(nums:number[],target:number){
        const hashTable :{[key:number]:number} = {}
        for (let i = 0; i < nums.length; i++) {
            let num = nums[i]
            //计算当前元素与target的差
            const complement = target - num
            if(complement in hashTable){
                return [hashTable[complement],i]
            }
            hashTable[num] = i
        }
    }

}
let a = new TwoSum().sumHas([2,7,11,15],9)
let b = new TwoSum().sumHas([2,5,5,11],10)
console.log(a,b)